home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / elv18src.zip / tinytcap.c < prev    next >
C/C++ Source or Header  |  1994-01-13  |  11KB  |  413 lines

  1. /* tinytcap.c */
  2.  
  3. /* This file contains functions which simulate the termcap functions.
  4.  *
  5.  * It doesn't access a "termcap" file.  Instead, it uses an initialized array
  6.  * of strings to store the entries.  Any string that doesn't start with a ':'
  7.  * is taken to be the name of a type of terminal.  Any string that does start
  8.  * with a ':' is interpretted as the list of fields describing all of the
  9.  * terminal types that precede it.
  10.  *
  11.  * Note: since these are C strings, you can't use special sequences like
  12.  * ^M or \E in the fields; your C compiler won't understand them.  Also,
  13.  * at run time there is no way to tell the difference between ':' and '\072'
  14.  * so I sure hope your terminal definition doesn't require a ':' character.
  15.  *
  16.  * getenv(TERM) on VMS checks the SET TERM device setting.  To implement
  17.  * non-standard terminals set the logical ELVIS_TERM in VMS. (jdc)
  18.  *
  19.  * Other possible terminal types are...
  20.  *     TERM_WYSE925    - "wyse925", a Wyse 50 terminal emulating Televideo 925
  21.  * ... or you could set $TERMCAP to the terminal's description string, which
  22.  * $TERM set up to match it.
  23.  *
  24.  * Note that you can include several terminal types at the same time.  Elvis
  25.  * chooses which entry to use at runtime, based primarily on the value of $TERM.
  26.  */
  27.  
  28.  
  29. #include "config.h"
  30. #if HAS_STDLIB
  31. # include <stdlib.h>
  32. #else
  33. extern char *getenv();
  34. #endif
  35. #include <stdio.h>    /* for 'sprintf()' */
  36.  
  37. /* decide which terminal descriptions should *always* be included. */
  38. #if MSDOS || OS2
  39. # define    TERM_NANSI
  40. # define    TERM_DOSANSI
  41. # ifdef RAINBOW
  42. #  define    TERM_RAINBOW
  43. # endif
  44. #endif
  45.  
  46. #if VMS
  47. # define    TERM_VT100
  48. # define    TERM_VT100W
  49. # define    TERM_VT52
  50. #endif
  51.  
  52. #if AMIGA
  53. # define    TERM_AMIGA    /* Internal Amiga termcap entry */
  54. /* # define    TERM_VT52    /* The rest of these are here for those */
  55. # define    TERM_VT100    /* people who want to use elvis over an */
  56. /* # define    TERM_NANSI    /* AUX: port (serial.device). */
  57. /* # define    TERM_DOSANSI    /* Take out all but AMIGA to save memory. */
  58. /* # define    TERM_MINIX    /* Vanilla ANSI? */
  59. /* # define    TERM_925    /* Hang a terminal off your Amiga */
  60. #endif
  61.  
  62. #if MINIX || UNIXV
  63. # define    TERM_MINIX
  64. #endif
  65.  
  66. #if COHERENT
  67. # define    TERM_COHERENT
  68. #endif
  69.  
  70. #if TOS
  71. # define    TERM_ATARI
  72. #endif
  73.  
  74. static char *termcap[] =
  75. {
  76. #ifdef TERM_AMIGA
  77. "AA",
  78. "amiga",
  79. "Amiga ANSI",
  80. /* Amiga termcap modified from version 1.3 by Kent Polk */
  81. ":co#80:li#24:am:bs:bw:xn:\
  82. :AL=\233%dL:DC=\233%dP:DL=\233%dM:DO=\233%dB:\
  83. :LE=\233%dD:RI=\233%dC:SF=\233%dS:SR=\233%dT:UP=\233%dA:IC=\233%d@:\
  84. :ae=\2330m:al=\233L:as=\2333m:bl=\007:bt=\233Z:cd=\233J:\
  85. :ce=\233K:cl=\013:cm=\233%i%d;%dH:dc=\233P:dl=\233M:do=\233B:\
  86. :kb=^H:ho=\233H:ic=\233@:is=\23320l:\
  87. :mb=\2337;2m:md=\2331m:me=\2330m:mh=\2332m:mk=\2338m:mr=\2337m:nd=\233C:\
  88. :rs=\033c:se=\2330m:sf=\233S:so=\2337m:sb=\233T:sr=\233T:ue=\23323m:\
  89. :up=\233A:us=\2334m:vb=\007:ve=\233\040p:vi=\2330\040p:\
  90. :k1=\2330~:k2=\2331~:k3=\2332~:k4=\2333~:k5=\2334~:\
  91. :k6=\2335~:k7=\2336~:k8=\2337~:k9=\2338~:k0=\2339~:\
  92. :s1=\23310~:s2=\23311~:s3=\23312~:s4=\23313~:s5=\23314~:\
  93. :s6=\23315~:s7=\23316~:s8=\23317~:s9=\23318~:s0=\23319~:\
  94. :kd=\233B:kl=\233D:kn#10:kr=\233C:ku=\233A:le=\233D:\
  95. :kP=\233T:kN=\233S:kh=\233\040A:kH=\233\040@:",
  96. #endif
  97.  
  98. #ifdef TERM_NANSI
  99. "fansi",
  100. "nnansi",
  101. "nansi",
  102. "pcbios",
  103. ":al=\033[L:dl=\033[M:am:bs:ce=\033[K:cl=\033[2J:\
  104. :cm=\033[%i%d;%dH:co#80:do=\033[B:\
  105. :k1=#;:k2=#<:k3=#=:k4=#>:k5=#?:k6=#@:k7=#A:k8=#B:k9=#C:k0=#D:\
  106. :s1=#T:s2=#U:s3=#V:s4=#W:s5=#X:s6=#Y:s7=#Z:s8=#[:s9=#\\:s0=#]:\
  107. :c1=#^:c2=#_:c3=#`:c4=#a:c5=#b:c6=#c:c7=#d:c8=#e:c9=#f:c0=#g:\
  108. :a1=#h:a2=#i:a3=#j:a4=#k:a5=#l:a6=#m:a7=#n:a8=#o:a9=#p:a0=#q:\
  109. :kd=#P:kh=#G:kH=#O:kI=#R:kD=#S:kl=#K:kN=#Q:kP=#I:kr=#M:ku=#H:\
  110. :li#25:md=\033[1m:me=\033[m:nd=\033[C:se=\033[m:so=\033[7m:\
  111. :ue=\033[m:up=\033[A:us=\033[4m:",
  112. #endif
  113.  
  114. #ifdef TERM_DOSANSI
  115. #if !ANY_UNIX
  116. "ansi",
  117. #endif
  118. "dosansi",
  119. ":am:bs:ce=\033[K:cl=\033[2J:\
  120. :cm=\033[%i%d;%dH:co#80:do=\033[B:\
  121. :k1=#;:k2=#<:k3=#=:k4=#>:k5=#?:k6=#@:k7=#A:k8=#B:k9=#C:k0=#D:\
  122. :s1=#T:s2=#U:s3=#V:s4=#W:s5=#X:s6=#Y:s7=#Z:s8=#[:s9=#\\:s0=#]:\
  123. :c1=#^:c2=#_:c3=#`:c4=#a:c5=#b:c6=#c:c7=#d:c8=#e:c9=#f:c0=#g:\
  124. :a1=#h:a2=#i:a3=#j:a4=#k:a5=#l:a6=#m:a7=#n:a8=#o:a9=#p:a0=#q:\
  125. :kd=#P:kh=#G:kH=#O:kI=#R:kD=#S:kl=#K:kN=#Q:kP=#I:kr=#M:ku=#H:\
  126. :li#25:md=\033[1m:me=\033[m:nd=\033[C:se=\033[m:so=\033[7m:\
  127. :ue=\033[m:up=\033[A:us=\033[4m:",
  128. #endif
  129.  
  130. #ifdef TERM_RAINBOW
  131. "vt220",
  132. "rainbow",
  133. ":al=\033[L:dl=\033[M:am:bs:ce=\033[K:cl=\033[2J:\
  134. :cm=\033[%i%d;%dH:co#80:do=\033[B:kd=\033[B:kl=\033[D:\
  135. :kr=\033[C:ku=\033[A:kP=\033[5~:kN=\033[6~:kI=\033[2~:\
  136. :li#24:md=\033[1m:me=\033[m:nd=\033[C:se=\033[m:so=\033[7m:\
  137. :ue=\033[m:up=\033[A:us=\033[4m:xn:",
  138. #endif
  139.  
  140. #ifdef TERM_VT100
  141. "vt100-80",
  142. "vt101-80",
  143. ":am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
  144. :co#80:do=\033[B:k0=\033[20~:k1=\033[1~:\
  145. :k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
  146. :k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
  147. :kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
  148. :kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:nd=\033[C:\
  149. :se=\033[m:so=\033[7m:\
  150. :ue=\033[m:up=\033[A:us=\033[4m:xn:",
  151. "vt200-80",
  152. "vt300-80",
  153. "vt102-80",
  154. ":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
  155. :co#80:dl=\033[M:do=\033[B:k0=\033[20~:k1=\033[1~:\
  156. :k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
  157. :k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
  158. :kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
  159. :kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:nd=\033[C:\
  160. :se=\033[m:so=\033[7m:\
  161. :ue=\033[m:up=\033[A:us=\033[4m:xn:",
  162. #endif
  163.  
  164. #ifdef TERM_VT100W
  165. "vt100-w",
  166. "vt100-132",
  167. "vt101-w",
  168. "vt101-132",
  169. ":am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
  170. :co#132:do=\033[B:k0=\033[20~:k1=\033[1~:\
  171. :k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
  172. :k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
  173. :kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
  174. :kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:nd=\033[C:\
  175. :se=\033[m:so=\033[7m:\
  176. :ue=\033[m:up=\033[A:us=\033[4m:xn:",
  177. "vt200-w",
  178. "vt300-w",
  179. "vt102-w",
  180. "vt200-132",
  181. "vt300-132",
  182. "vt102-132",
  183. ":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
  184. :co#132:dl=\033[M:do=\033[B:k0=\033[20~:k1=\033[1~:\
  185. :k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
  186. :k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
  187. :kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
  188. :kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:nd=\033[C:\
  189. :se=\033[m:so=\033[7m:\
  190. :ue=\033[m:up=\033[A:us=\033[4m:xn:",
  191. #endif
  192.  
  193. #ifdef TERM_VT52
  194. "vt52",
  195. ":do=\n:le=\b:up=\033A:nd=\033C:cm=\033Y%+ %+ :ti=\033e\033v:\
  196. :sr=\033I:cd=\033J:ce=\033K:cl=\033H\033J:co#80:li#24:\
  197. :ku=\033A:kd=\033B:kr=\033C:kl=\033D:kb=\b:pt:am:xn:bs:",
  198. #endif
  199.  
  200. #ifdef TERM_MINIX
  201. "minix",
  202. "ansi",
  203. "AT386",
  204. ":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
  205. :co#80:dl=\033[M:do=\033[B:k0=\033[20~:k1=\033[1~:\
  206. :k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
  207. :k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
  208. :kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
  209. :kr=\033[C:ku=\033[A:li#25:md=\033[1m:me=\033[m:nd=\033[C:\
  210. :se=\033[m:so=\033[7m:ue=\033[m:up=\033[A:us=\033[4m:",
  211. #endif /* MINIX */
  212.  
  213. #ifdef TERM_COHERENT
  214. "coherent",
  215. "ansipc",
  216. ":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
  217. :co#80:dl=\033[M:do=\033[B:k0=\033[0x:k1=\033[1x:k2=\033[2x:\
  218. :k3=\033[3x:k4=\033[4x:k5=\033[5x:k6=\033[6x:\
  219. :k7=\033[7x:k8=\033[8x:k9=\033[9x:kd=\033[B:kh=\033[H:\
  220. :kH=\033[24H:kI=\033[@:kD=\033[P:kl=\033[D:kN=\033[U:kP=\033[V:\
  221. :kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:\
  222. :nd=\033[C:se=\033[m:so=\033[7m:ue=\033[m:up=\033[A:\
  223. :us=\033[4m:",
  224. #endif /* COHERENT */
  225.  
  226. #ifdef TERM_ATARI
  227. "atari-st",
  228. "vt52",
  229. ":al=\033L:am:bs:ce=\033K:cl=\033E:cm=\033Y%i%+ %+ :\
  230. :co#80:dl=\033M:do=\033B:\
  231. :k1=#;:k2=#<:k3=#=:k4=#>:k5=#?:k6=#@:k7=#A:k8=#B:k9=#C:k0=#D:\
  232. :s1=#T:s2=#U:s3=#V:s4=#W:s5=#X:s6=#Y:s7=#Z:s8=#[:s9=#\\:s0=#]:\
  233. :c1=#^:c2=#_:c3=#`:c4=#a:c5=#b:c6=#c:c7=#d:c8=#e:c9=#f:c0=#g:\
  234. :a1=#h:a2=#i:a3=#j:a4=#k:a5=#l:a6=#m:a7=#n:a8=#o:a9=#p:a0=#q:\
  235. kd=#P:kh=#G:kI=#R:kl=#K:kr=#M:ku=#H:li#25:nd=\033C:se=\033q:\
  236. :so=\033p:te=:ti=\033e\033v:up=\033A:",
  237. #endif
  238.  
  239. #ifdef TERM_925
  240. "wyse925",
  241. ":xn@:\
  242. :hs:am:bs:co#80:li#24:cm=\033=%+ %+ :cl=\033*:cd=\033y:\
  243. :ce=\033t:is=\033l\033\":\
  244. :al=\033E:dl=\033R:im=:ei=:ic=\033Q:dc=